import { Injectable } from '@angular/core';

import { HttpClient } from "@angular/common/http"
import { MenuManageService } from "../../system-manage/menu-manage/menu-manage.service"
import { map } from 'rxjs/operators';
import { Router, ActivatedRoute } from '@angular/router';
import { Location } from '@angular/common';

@Injectable({
    providedIn: 'root'
})

export class SideMenuService {

    constructor(
        private http: HttpClient,
        private menuManageService: MenuManageService,
        private router: Router,
        private activeRouter: ActivatedRoute,
        private location: Location
    ) { }

    apiGetList() {
        return this.menuManageService.apiBuildList().pipe(
            map(data => {
                return this.addKey(data, 1)
            })
        )
    }
    addKey(data, level) {
        data.forEach(item => {
            let _level = level
            item.open = false;
            item.level = _level;
            if (item.children && item.children.length > 0) {
                this.addKey(item.children, ++_level)
            }
        });
        return data
    }
    
}
